/*
 * Copyright 2020, GeoSolutions Sas.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree.
 */

// **************
// Theme
// **************

#gn-components-theme(@theme-vars) {
    .gn-filter-form {
        .color-var(@theme-vars[main-color]);
        .background-color-var(@theme-vars[main-bg]);
    }

    .gn-filter-form-divider {
        .background-color-var(@theme-vars[main-variant-bg]);
    }
    .gn-facet-wrapper {
        .facet {
            &:focus-within {
                .outline-color-var(@theme-vars[focus-color]);
            }
        }
    }

    .gn-accordion, .gn-group {
        .border-color-var(@theme-vars[main-border-color]);
        .accordion-title {
            .color-var(@theme-vars[main-color]);
            .background-color-var(@theme-vars[main-bg]);
            &:hover {
                .background-color-var(@theme-vars[main-hover-bg]);
            }
            &:focus-within {
                .outline-color-var(@theme-vars[focus-color]);
            }
        }
        .gn-facet-wrapper {
            .border-bottom-color-var(@theme-vars[main-border-color]);
            .facet {
                &.active {
                    .background-color-var(@theme-vars[primary]);
                    .color-var(@theme-vars[primary-contrast]);
                }
                &:hover:not(&.active) {
                    .background-color-var(@theme-vars[main-hover-bg]);
                    .color-var(@theme-vars[main-color]);
                    .facet-children {
                        .background-color-var(@theme-vars[main-bg]);
                        .color-var(@theme-vars[main-color]);
                    }
                }
            }

        }
    }
    .gn-tabs {
        > .nav {
            .background-color-var(@theme-vars[main-bg]);
        }
    }
}

// **************
// Layout
// **************

.gn-filter-form {
    color: @gn-main-color;
    background-color: @gn-main-bg;
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    height: 100%;

    .gn-filter-form-header {
        padding: 0.5rem;
        display: flex;
        align-items: center;
        margin-bottom: 0.5rem;
    }

    .gn-filter-form-body {
        display: flex;
        flex-direction: column;
        flex: 1;
        position: relative;
        width: 100%;
        overflow-y: auto;

        .gn-filter-form-content {
            position: absolute;
            padding: 1rem;
            width: 100%;
            padding-top: 0;

            .form-group {
                margin-bottom: 0.5rem;
            }

            .accordion-items {
                .form-group {
                    margin-bottom: 0;
                }

                .checkbox {
                    margin-bottom: 0;
                    margin-top: 0;
                }
            }
        }
    }

    .gn-filter-form-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex: 1;
        padding: 0 0.5rem;
    }

    .gn-filter-form-divider {
        width: calc(100% - 0.5rem);
        height: 1px;
        margin: 1rem 0.25rem;
    }

    .gn-filter-form-link,
    .gn-filter-form-group-title {
        margin: 0.5rem 0;
    }
}

.gn-main-home {
    width: 100%;
    padding: 0;
    margin-right: auto;
    margin-left: auto;
}

.gn-sub-filter-items {
    .checkbox {
        &:first-of-type {
            margin-top: 0.3rem;
        }

        &:last-child {
            margin-bottom: 0;
        }
    }

    .gn-facet-wrapper {
        padding-left: 0;

        .facet {
            cursor: pointer;

            &.active {
                >span {
                    font-weight: bold;
                }
            }

            span {
                margin-right: 0.25rem;
            }
        }
    }

    &:last-child {
        .gn-facet-wrapper {
            border-bottom: none;
        }
    }
}

.gn-facet-wrapper {
    border-bottom-width: 0.08rem;
    border-bottom-style: solid;

    .facet {
        position: relative;
        display: flex;
        padding: 0.1rem 0.3rem;
        cursor: pointer;
        > span:not(.facet-count) {
            flex: 1;
        }
        input[type="checkbox"] {
            display: block;
            width: 0;
            height: 0;
            overflow: hidden;
            opacity: 0;
        }
        &.active {
            >span {
                font-weight: bold;
            }
        }
        &:focus-within {
            outline: 1px solid transparent;
        }
        span {
            margin-right: 0.25rem;
        }
    }

    .facet-children {
        .gn-sub-filter-items {
            padding-left: 0.6rem;
        }
    }
}
.gn-group {
    margin: 0.5rem 0;
    .group-title-label {
        margin: 0.2rem 0;
        font-weight: 700;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .group-body {
        .group-items {
            padding: 0 0 0.6rem 0.8rem;
            overflow-y: auto;
            > span {
                font-weight: lighter;
                font-size: 0.8rem;
            }
            .form-group {
                margin-bottom: 0;
                .checkbox {
                    label {
                        width: 100%;
                    }
                }
            }
            .gn-facet-wrapper {
                padding: 0.25rem 0;
                background: inherit;
                border-bottom-width: 1px;
                border-bottom-style: solid;
                .facet {
                    &.active {
                        > span {
                            font-weight: normal;
                        }
                    }
                }
            }
        }
    }
}

.gn-accordion {
    margin-bottom: 0.5rem;
    border-width: 0.08rem;

    .accordion-title {
        display: flex;
        cursor: pointer;
        font-weight: 600;
        padding: 0.4rem 0.25rem;
        padding-left: 0;
        .accordion-title-label {
            flex: 1;
            display: flex;
            padding-right: 1rem;
            padding-left: 0.1rem;
        }
        button {
            display: block;
            width: 0;
            height: 0;
            opacity: 0;
            overflow: hidden;
        }
        &:focus-within {
            outline: 1px solid transparent;
        }
        .gn-spinner,
        .fa {
            display: inline-flex;
            width: 1rem;
            min-width: 1rem;
            height: 1.25rem;
            align-items: center;
        }
    }

    .accordion-body {
        .accordion-items {
            display: flex;
            flex-direction: column;
            padding: 0.2rem 0 0.6rem 0.8rem;
            overflow-y: auto;
            .form-group {
                padding-top: 0.6rem;
                .checkbox {
                    label {
                        width: 100%;
                    }
                }
            }
            .gn-facet-wrapper {
                padding: 0.25rem 0;
                background: inherit;
                border-bottom-width: 1px;
                border-bottom-style: solid;
                .facet {
                    &.active {
                        > span {
                            font-weight: normal;
                        }
                    }
                }
            }
        }
    }
}

.gn-label {
    display: flex;
    justify-content: space-between;
    width: 100%;
    .prefix {
        display: flex;
        align-items: center;
        i, img {
            margin-right: 0.375rem;
        }
        i {
            font-size: 1rem;
        }
        img {
            object-fit: contain;
            width: 1.5rem;
        }
        > span {
            max-width: 300px;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }
    .facet-count {
        margin-right: 0.625rem;
    }
}

.gn-tabs {
    padding: 0.5rem;
    > .nav {
        position: sticky;
        top: 2.5rem;
        z-index: 1;
        li {
            a {
                padding: 0.125rem;
            }
            a:focus {
                outline-color: transparent;
                outline-offset: 0px;
            }
        }
    }
    .tab-content {
        margin-top: 0.5rem;
    }
}